<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/public.css" media="all">
</head>
<body>
<div class="layuimini-container" id="app">
    <div class="layuimini-main">
        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
            <legend>批量取消维护</legend>
        </fieldset>
        <form class="layui-form" action="" lay-filter="example">
            <div class="layui-form-item">
                <label class="layui-form-label">区服ID</label>
                <div class="layui-input-block">
                    <input type="text" name="server_id" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input layui-disabled" disabled>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">区服名称</label>
                <div class="layui-input-block">
                    <input type="text" name="name" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input layui-disabled" disabled>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit="" lay-filter="demo1">提交</button>
                </div>
            </div>
        </form>
    </div>
</div>
<script src="/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="/js/common.js?v=5" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
    Id = urlParam('id')
    serverIds  =urlParam('serverIds')
    var namesEncoded = urlParam('name'); // 获取经过编码的names参数
    var namesDecoded1 = decodeURIComponent(namesEncoded); // 第一次解码
    var names = decodeURI(namesDecoded1); // 第二次解码
    new Vue({
        el:"#app",
        data:{
            id:Id,
            formData:{
                show:null,
                status:null,
                busy_status:null,
            }
        },
        methods:{
        },
        mounted:function() {
            var _this = this;
            layui.use(['form', 'laydate'], function () {
                var form = layui.form, layer = layui.layer, $ = layui.$,laydate=layui.laydate;
                laydate.render({
                    elem: '#maintain_at',
                    type: 'datetime',
                    trigger: 'click'
                });
                if(serverIds){
                    console.log('处理过的的：', names);
                    form.val('example', {
                        "server_id": serverIds,
                        "name": names,
                    })
                    form.render()
                }
                if (Id) {
                    $.get('/admin/server/' + Id, {}, function (res) {
                        var data = res.data;
                        form.val('example', {
                            "server_id": data.server_id,
                            "name": data.name,
                            "push_url": data.push_url,
                            "show": data.show,
                            "status": data.status,
                            "busy_status": data.busy_status,
                            "maintain_at": data.maintain_at,
                        })
                        _this.formData = data;
                        form.render()
                    })
                    //表单初始赋值
                }
                //监听提交
                form.on('submit(demo1)', function (data) {
                    var formData = data.field;
                    formData._method = 'put';
                    if(serverIds){
                        Id=serverIds
                    }
                    layer.confirm('再次确认，真的取消维护吗',{title:"提示",icon:3},function(){
                        $.post('/admin/server/' + Id +'/stopMaintain', formData, function (res) {
                            if (res.code === 0) {
                                layer.msg('success', {icon: 6, time: 500}, function () {
                                    parent.location.reload();//父页面刷新
                                })
                            } else {
                                layer.msg(res.msg, {icon: 5})
                            }
                        })
                    })
                    return false;
                });
                form.on('radio(status)',function(data){
                    _this.formData.status = data.value;
                })
                form.render();
            })
        }
    });
</script>

</body>
</html>